<?php require_once 'models/models_thongke.php';
$obtk=new models_thongke();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
		<title>
			jQuery gvChart plugin - Google Visualization Charts via jQuery
		</title>
        <link type="text/css" rel="stylesheet" href="public/gvchart/st.css"  />
		<script type="text/javascript" src="public/gvchart/go.js"></script>
		<script type="text/javascript" src="public/gvchart/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="public/gvchart/jquery.gvChart-1.0.1.min.js"></script>
		<script type="text/javascript">
		gvChartInit();
		jQuery(document).ready(function(){
			
			jQuery('#myTable4').gvChart({
				chartType: 'ColumnChart',
				gvSettings: {
					vAxis: {title: 'Lợi nhuận'},
					hAxis: {title: 'Tháng'},
					width: 720,
					height: 300
					}
			});
			
		
		});
		</script>
	
	</head>
	<body>
		<div class="main">
			<h2 id="column"></h2>
			
			<table id='myTable4'>
				<caption>Lợi nhuận</caption>
					<thead>
					
						<tr>
							<th></th>
                            <?php 
                        
                            for($i=1;$i<=12;$i++)
							{?>
							<th><?php echo $i ;?></th>
							<?php }?>
						</tr>
					</thead>
					<tbody>
					 <?php 
					  
					for($j=$_POST['tunam'];$j<=$_POST['dennam'];$j++)
							{?>
						<tr>		
						<th><?php echo $j;?></th>
						<?php 	
						
						 
						for($a=1;$a<=12;$a++){
							 
							if($a<10)
							{
							$ngay ="0".$a."/".$j;	
							}else
							{
							$ngay =$a."/".$j;	
							}
							$data['listthang']=$obtk->listhdthang($ngay);
							//var_dump($data['listthang']);
				if(!$data['listthang']){
					$tongloinhuan=0;
				}else{
					$tongloinhuan=0;
					$tongtien=0;
					foreach ($data['listthang'] as $key => $hd){
			$data['listcthoadon']=$obtk->listcthoadon($hd['MaHD']);
			if(is_array($data['listcthoadon']))
			{
			foreach ($data['listcthoadon'] as $key =>$cthoadon){
				if(is_array($data['listmh'])){
					foreach ($data['listmh']  as $key =>$mh){
						if($cthoadon['MaMH']==$mh['MaMH']){
							$nhap=$obtk->listctn($mh['MaMH']);
							//var_dump($nhap);
			
 								$thanhtien=$cthoadon['DonGiaBan']*$cthoadon['SoLuongBan'];
							
								$loinhuan=$thanhtien-($nhap['DonGiaNhap']*$cthoadon['SoLuongBan']);
								
								
							
								 $tongtien+=$thanhtien;
								 $tongloinhuan+=$loinhuan;
								 
							}
							}
						}	
					}
				}
						}
					
				
				
				$tongloinhuan;
				
				}
				
	?>



		
						
						
						<td><?php echo $tongloinhuan;?></td>
						<?php }?>
						</tr>	
					<?php }?>
						
						
					
				</tbody>
				
				
			</table>
			
			
		</div>
	</body>
</html>


